package com.zhao.practice;

import com.alibaba.fastjson.JSONObject;
import com.zhao.pojo.User;
import com.zhao.utils.ElasticsearchUtils;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.net.UnknownHostException;
import java.util.Date;

@Slf4j
public class InsertText {
    public static void main(String[] args) throws UnknownHostException {
        TransportClient transportClient = ElasticsearchUtils.getTransportClient();
        User user = new User("李四", 18, "我叫张三，我来自黄金岛。", new Date(System.currentTimeMillis()));
        IndexResponse indexResponse = transportClient.prepareIndex("ems", "emp")
                .setSource(JSONObject.toJSONStringWithDateFormat(user, "yyyy-MM-dd"), XContentType.JSON)
                .get();
        log.info("插入操作状态：{}", indexResponse.status());
    }
}
